package jm.nj.demo14mian.demo03;



import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

/*
* Socket(String host,int port)  创建一个流套接字并将其指定发送的主机ip,端口号
*
* Socket(InetAddress address,int port)
*
* TCP客户端
*
* 1.创建Socket对象(指定要连接的服务器地址与端口号)
* 2.获得服务器端返回来的信息
* 3.关闭流资源
*
* */
public class DemoSocket {
    public static void main(String[] args) throws IOException {
        //创建Socket
        Socket s = new Socket("127.0.0.1",8888);
        //获得服务器端的返回信息
        InputStream in = s.getInputStream();

        byte[] buffer = new byte[1024];

        //记录

        int leng = in.read(buffer);

        //显示
        System.out.println(new String(buffer, 0,leng));

        in.close();
        s.close();
    }
}
